package cn.tedu.charging.order.service;

import cn.tedu.charging.common.pojo.param.OrderAddParam;
import cn.tedu.charging.common.protocol.JsonResult;
import cn.tedu.charging.order.feign.DeviceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements OrderService{
    //注入一个服务调用客户端 设备
    @Autowired
    private DeviceClient deviceClient;
    @Override
    public String createOrder(OrderAddParam param) {
        //1.根据入参参数 检查枪状态
        checkGun(param.getGunId());
        return "abc";
    }

    private void checkGun(Integer gunId) {
        JsonResult<Boolean> result = deviceClient.checkGun(gunId);
        Boolean data = result.getData();
        if (!data){
           throw new RuntimeException("此枪不可用");
        }
    }
}
